#!/bin/sh
### The script execute post deployments steps
### It should run after deploy-review is finished
### This is called in .gitlab_ci.yml post-deploy job

# Change to the repository root folder via the scripts location
cd "$(dirname "$0")"/..
. k8s/includes/ci-environment
. k8s/includes/log
########################################
set -x  # output all commands
########################################

###Local epf/experiment image upload ###
export LOCAL_CI_REGISTRY="$MLREEF_DOCKER_REGISTRY"
export LOCAL_CI_REGISTRY_USER=root

if [ -n "${LOCAL_CI_REGISTRY+x}" ] && [ -n "${LOCAL_CI_REGISTRY_USER+x}" ] && [ -n "${GITLAB_ADMIN_TOKEN+x}" ]; then
          echo "$MLREEF_GITLAB_ROOT_PASSWORD" | docker login "$LOCAL_CI_REGISTRY" --username="$LOCAL_CI_REGISTRY_USER" --password-stdin
fi

echo "Building $LOCAL_EXPERIMENT_IMAGE_PATH"
docker build --tag "$LOCAL_EXPERIMENT_IMAGE_PATH" -f images/experiment/Dockerfile images/experiment
docker push "$LOCAL_EXPERIMENT_IMAGE_PATH"
log "$LOCAL_EXPERIMENT_IMAGE_PATH has been successfully uploaded "

echo "Building $LOCAL_EPF_IMAGE_PATH"
docker build --tag "$LOCAL_EPF_IMAGE_PATH" -f epf/Dockerfile epf
docker push "$LOCAL_EPF_IMAGE_PATH"
log "$LOCAL_EPF_IMAGE_PATH has been successfully uploaded "

###Local epf/experiment image upload ends ###

